import { Fragment } from '@/components/Fragment';
import { Button, Icon, Flex, Text, Alert, Link } from '@aws-amplify/ui-react';
import { IconDemo } from './demo';
import { Example, ExampleCode } from '@/components/Example';
import { ComponentStyleDisplay } from '@/components/ComponentStyleDisplay';
import {
AccessibilityIconExample,
DefaultIconExample,
CustomIconExample,
IconColorExample,
IconSizesExample,
CustomIconWithSvgExample,
CustomIconWithPathsExample,
CustomIconWithLibExample,
ViewboxExample,
} from './examples';
## Demo
Icons should be thought of as plain text; they inherit the size and color of their context or can be set directly. Icons themselves do not have any state or handlers, those should be at a higher level like a button. Amplify UI does not include any icons other than the ones Amplify UI components like [Alert](/components/alert) and [Expander](/components/expander) use.
## Usage
Import the Icon component and styles.
```jsx file=./examples/DefaultIconExample.tsx
```
### Built-in iconset
The built-in icons were removed in version `3.0`. You can use the
[react-icons](https://react-icons.github.io/react-icons/) package or other
React icon libraries in its place.
```jsx
// Removed
import {ICON_NAME} from '@aws-amplify/ui-react';
// Suggested
import {ICON_NAME} from 'react-icons/md';`
```
## Custom icon
### Using path data
To create a custom icon using a path data, provide the `d` attribute in svg to `pathData` prop.
```jsx file=./examples/CustomIconExample.tsx
```
You can use the `viewBox` prop to change the SVG [`viewBox`](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox). Both `width` and `height` default to `24`.
```jsx file=./examples/ViewboxExample.tsx
```
### Using SVG
You can also pass SVG elements as children to the `Icon` component if you have more than 1 path or want to provide other SVG attributes like [`stroke`](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke)
```jsx file=./examples/CustomIconWithSvgExample.tsx
```
You can also optionally use a `paths` array of path-like objects that will be mapped to `` elements.
```jsx file=./examples/CustomIconWithPathsExample.tsx
```
### Using a library
To use an icon library like [React Icons](https://react-icons.github.io/react-icons/), import the desired icon and pass it to the `as` prop.
```jsx file=./examples/CustomIconWithLibExample.tsx
```
Here are some good open source icon libraries:
- React icons
- Hero icons
## Styling
### Target classes
### Sizes
Icon size matches the font-size of the container. Adjust the font-size to set a specific height.
_Inherited size from button sizes_
```jsx file=./examples/IconSizesExample.tsx
```
### Color
Use the `color` prop to change the Icon color. The fill of the path inside the SVG is set to [`currentColor`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentcolor_keyword)(inherits color from current font color).
```jsx file=./examples/IconColorExample.tsx
```
## Accessibility
The Icon component does not require a label by default because there are a number of ways to use an Icon in an accessible way:
- You can set an `aria-label` attribute on the Icon
- You can use a `` element when passing SVG elements as the child of the Icon
- You can use the Icon decoratively, when a label would be redundant.
```jsx file=./examples/AccessibilityIconExample.tsx
```